package com.example.xinwenkehuduan;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import cn.bmob.v3.BmobUser;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.LogInListener;
import cn.bmob.v3.util.V;

public class LoginActivity extends AppCompatActivity {
    private EditText edUserName;
    private EditText edPassWord;
    private Button btnLogin;
    private Button btnRes;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        setTitle("用户登陆");


        edUserName = findViewById(R.id.ed_username);
        edPassWord = findViewById(R.id.ed_password);
        btnLogin = findViewById(R.id.btn_login);
        btnRes   = findViewById(R.id.btn_res);

        btnLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                BmobUser.loginByAccount(edUserName.getText().toString(),
                        edPassWord.getText().toString(),
                        new LogInListener<BmobUser>() {
                            @Override
                            public void done(BmobUser bmobUser, BmobException e) {
                                if (e== null){
                                    Toast.makeText(LoginActivity.this,"登陆成功",Toast.LENGTH_SHORT).show();
                                    finish();
                                }
                            }
                        });
            }
        });


        btnRes.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(LoginActivity.this,ResActivity.class);
                startActivity(intent);
            }
        });

    }
}
